package com.mall.product.controller;

import com.mall.common.utils.BaseResult;
import com.mall.common.utils.PageUtils;
import com.mall.common.valid.group.AddGroup;
import com.mall.common.valid.group.UpdateGroup;
import com.mall.common.valid.group.UpdateStatusGroup;
import com.mall.product.entity.BrandEntity;
import com.mall.product.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;




/**
 * 品牌
 *
 * @author rose
 * @email rose@126.com
 * @date 2023-08-27 17:22:02
 */
@RestController
@RequestMapping("product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("product:brand:list")
    public BaseResult list(@RequestParam Map<String, Object> params){

        PageUtils page = brandService.queryPage(params);

        return BaseResult.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    // @RequiresPermissions("product:brand:info")
    public BaseResult info(@PathVariable("brandId") Long brandId){

		BrandEntity brand = brandService.getById(brandId);

        return BaseResult.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("product:brand:save")
    public BaseResult save(@Validated({AddGroup.class}) @RequestBody BrandEntity brand){

		brandService.save(brand);

        return BaseResult.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("product:brand:update")
    public BaseResult updateDetail(@Validated({UpdateGroup.class})@RequestBody BrandEntity brand){

		brandService.updateDetail(brand);

        return BaseResult.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update/status")
    // @RequiresPermissions("product:brand:update")
    public BaseResult updateStatus(@Validated({UpdateStatusGroup.class})@RequestBody BrandEntity brand){

        brandService.updateById(brand);

        return BaseResult.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("product:brand:delete")
    public BaseResult delete(@RequestBody Long[] brandIds){

		brandService.removeByIds(Arrays.asList(brandIds));

        return BaseResult.ok();
    }

}
